$(function() {
	
	$("input[name='ad_title']").val("");
	$("input[name='ad_weight']").val("");
	$("input[name='ad_link']").val("");
	
	// 提交
	$(".submit_btn").click(function() {
		var title = $("input[name='ad_title']").val();
		var weight = $("input[name='ad_weight']").val();
		var url = $("input[name='ad_fileurl']").val();
		var link = $("input[name='ad_link']").val();

		var flag = true;
		if(title == '' || title.length<1 || title.length>30){
			$("#validation_title").addClass("has-error");
			flag = false;
		}else{
			$("#validation_title").removeClass("has-error");
		}
		if(weight == '' || weight.length<1 || weight.length>2){
			$("#validation_weight").addClass("has-error");
			flag = false;
		}else{
			$("#validation_weight").removeClass("has-error");
		}
		if(url == '' || url.length<1 || url.length>256){
			$("#validation_url").addClass("has-error");
			flag = false;
		}else{
			$("#validation_url").removeClass("has-error");
		}
		
		if(flag == false){
			return false;
		}
		
		// 访问后台添加分组
		$.post("?c=admanage&a=submit_add", {
			title : title,
			weight : weight,
			url : url,
			link : link
		}, function(data) {
			if(data == '1')
			{
				// 添加成功
				window.location.href = "?c=admanage&a=index";
			}
			else 
			{
				alert("发生未知异常，请稍后重试或联系八鲜生鲜铺客服");
			}
		});
		return false;
	});
});